
import java.util.Random;

public class RandomStrategy implements Strategy{
	private int width;
	private int height;
	/**
	 * returns direction of monsters movement
	 */
	public int SelectDirection(Thing map[][], int xMonster, int yMonster, int xPacman, int yPacman) {
		width = map.length;
		height = map[0].length;
		int dir = new Random().nextInt(4);
		if ((dir == 0) && ((yMonster == 0) || ((map[xMonster][yMonster-1] != null) && (map[xMonster][yMonster-1].getClass() == Wall.class)))) {
			return SelectDirection(map, xMonster, yMonster, xPacman, yPacman);
		}
		if ((dir == 1) && ((xMonster == width-1) || ((map[xMonster+1][yMonster] != null) && (map[xMonster+1][yMonster].getClass() == Wall.class)))) {
			return SelectDirection(map,  xMonster, yMonster, xPacman, yPacman);
		}
		if ((dir == 2) && ((yMonster == height-1) || ((map[xMonster][yMonster+1] != null) && (map[xMonster][yMonster+1].getClass() == Wall.class)))) {
			return SelectDirection(map,  xMonster, yMonster, xPacman, yPacman);
		}
		if ((dir == 3) && ((xMonster == 0) || ((map[xMonster-1][yMonster] != null) && (map[xMonster-1][yMonster].getClass() == Wall.class)))) {
			return SelectDirection(map, xMonster, yMonster, xPacman, yPacman);	
		}		
		return dir;
	}
	
}

